import { fileURLToPath, URL } from "node:url";
import { resolve } from "path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
	plugins: [vue()],
	server: {
		host: "0.0.0.0",
		proxy: {
			"/szbigdataFourServicesTest": {
				target: "http://www.zhcgdsj.suzhou.gov.cn",
				changeOrigin: true,
				rewrite: path =>
					path.replace(/^\/szbigdataFourServicesTest/, "szbigdataFourServicesTest"),
			},
		},
	},
	build: {
		lib: {
			entry: resolve(__dirname, "./src/export.ts"),
			name: "vue-mobile-hxq",
			fileName: format => `build.${format}.ts`,
		},
		rollupOptions: {
			// 确保外部化处理那些你不想打包进库的依赖
			external: ["vue"],
			output: {
				// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
				globals: {
					vue: "Vue",
				},
			},
		},
	},
	resolve: {
		alias: {
			"@": fileURLToPath(new URL("./src", import.meta.url)),
			components: fileURLToPath(new URL("./src/components", import.meta.url)),
			api: fileURLToPath(new URL("./src/api", import.meta.url)),
			asstes: fileURLToPath(new URL("./src/assets", import.meta.url)),
			store: fileURLToPath(new URL("./src/store", import.meta.url)),
			style: fileURLToPath(new URL("./src/style", import.meta.url)),
			views: fileURLToPath(new URL("./src/views", import.meta.url)),
			utils: fileURLToPath(new URL("./src/utils", import.meta.url)),
		},
	},
	css: {
		preprocessorOptions: {
			scss: {
				additionalData: '@import "./src/style/mixin.scss";',
			},
		},
	},
});
